<?php

require($_SERVER['DOCUMENT_ROOT'] . "/bootstrap.php");
$email = $session_email;
$profile1 = mysql_query(@"
    select * from user where email='$email'");
while ($row = mysql_fetch_array($profile1)) {
	$profile = $row;
}

function create_captcha() {
	$salt = "abchefghjkmnpqrstuvwxyz0123456789";
	srand((double) microtime() * 1000000);
	$i = 0;
	$new_captcha = '';
	while ($i <= 3) {
		$num = rand() % 33;
		$tmp = substr($salt, $num, 1);
		$new_captcha = $new_captcha . $tmp;
		$i++;
	}
	return $new_captcha;
}

if (!isset($_POST['updateuser'])) {
	//$founduser = 0;
	$captcha = create_captcha();
	$smarty->assign("captcha", $captcha);
	//$smarty->assign("founduser", $founduser);
}
if (isset($_POST['updateuser'])) {
	$pass = md5($_POST['pass']);
	$fullname = $_POST['fullname'];
	$telephone = $_POST['telephone'];
	$address = $_POST['address'];
	
		//die();
	if($pass==""){
		die(egaga);
		$sql = mysql_query(@"update user set fullname='$fullname',phone=$telephone,address='$address' where email='$email'");
	}
		else{
			
		$sql = mysql_query(@"update user set fullname='$fullname',pass='$pass',phone=$telephone,address='$address' where email='$email'");		
		
	}
	echo '<script type="text/javascript">';
	echo 'alert("Cập nhật xong!");';
	echo 'setTimeout("top.location.href =' . "'/'" . '",0);';
	echo "</script>";
	die();

}
$smarty->assign("profile", $profile);
$smarty->display("../templates/profileuser/index.tpl");